
package com.cloud.service.Impl;

import com.cloud.dto.ProjectDto;
import com.cloud.dto.TeamDto;
import com.cloud.dto.UserDto;
import com.cloud.entity.Project;
import com.cloud.service.ProjectService;
import com.cloud.service.TeamService;
import com.cloud.service.AdminService;
import com.cloud.service.UserService;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminService adminService;
    @Autowired
    UserService userService;
    @Autowired
    TeamService teamService;
    @Autowired
    ProjectService projectService;

    @Override
    public UserDto findUserById(Integer userId){
        return userService.getUerById(userId);
    }

    @Override
    public List<UserDto> findUserByName(String userName){
        return userService.findUserByName(userName);
    }

    @Override
    public TeamDto findTeamById(Integer teamId){
        return teamService.getTeamById(teamId);
    }

    @Override
    public TeamDto findTeamByName(String teamName){
        return teamService.getTeamByName(teamName);
    }

    @Override
    public ProjectDto findProById(Integer projectId){
        Project project=projectService.getProjectById(projectId);
        ProjectDto projectDto=new ProjectDto();
        BeanUtils.copyProperties(project,projectDto);
        return projectDto;
    }

    // MapperFacade对象注入
    @Autowired
    private MapperFacade mapperFacade;
    @Override
    public List<ProjectDto> findProByName(String projectName){
        List<Project> projectList=projectService.getProjectByName(projectName);
        List<ProjectDto> projectDtoList=new ArrayList<>();
        projectDtoList = mapperFacade.mapAsList(projectList, ProjectDto.class);
        return projectDtoList;
    }
}
